<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.bootcss.com/vue/2.7.9/vue.min.js"></script>
</head>
<body style="overflow: hidden;margin: 0px;padding: 0px;">
<div id="app" style="width: 100%;text-align: center;">
    <div>当前窗口ID: {{browserId}}</div>
    <div>当前通道ID: {{frameId}}</div>
    <div>IPC同步当前时间: {{dateTime}}</div>
    <div>JS-IPC同步当前时间: {{ipcDateTime}}</div>
    <div>OS-Info: {{osInfo}}</div>
    <button @click="ipcGetBrowserId">通过IPC获取当前窗口ID</button>
    <button @click="ipcGetChannelId">通过IPC获取当前窗口通道ID</button>
</div>
<style>
</style>
</body>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                browserId: "browserId",
                frameId: "frameId",
                dateTime: "--:--:-- --:--:--",
                ipcDateTime: "--:--:-- --:--:--",
                osInfo: "osInfo"
            }
        },
        mounted: function () {
            this.init();
            let vm = this;
            ipc.on("dateTime", function (dateTime) {
                vm.dateTime = dateTime
            });
        },
        methods: {
            init: function () {
                this.browserId = process.browserId
                this.frameId = process.frameId
                let vm = this;
                ipc.emit("os-info", function (result) {
                    vm.osInfo = result
                });
                setInterval(function () {
                    ipc.emit("ipcGetDateTime", function (result) {
                        vm.ipcDateTime = result
                    })
                }, 1000)
            },
            ipcGetBrowserId: function () {
                let vm = this;
                ipc.emit("ipcGetBrowserId", function (result) {
                    console.log("result", result)
                    vm.browserId = "ipc - " + result
                })
            },
            ipcGetChannelId: function () {
                let vm = this;
                ipc.emit("ipcGetChannelId", function (result) {
                    console.log("result", result)
                    vm.frameId = "ipc - " + result
                })
            }
        }
    })
</script>
</html>